﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ExRev.Engine.Utils
{
    public class HtmlLogger : Logger
    {
        internal HtmlLogger(string name, string path)
            : base(name, path)
        {
            Extention = ".html";
        }

        public override bool Log(LogLevel level, string message)
        {
            if (string.IsNullOrEmpty(message)) {
                return false;
            }

            StringBuilder sb = new StringBuilder();
            string messageLevel;

            sb.Append("<div style=\"font-family:'Courier New';color:");

            switch (level) {
                case LogLevel.Debug:
                    sb.Append("#F5B800");
                    messageLevel = "&nbsp;&nbsp;&nbsp;&nbsp; [Debug] ";
                    break;
                case LogLevel.Info:
                    sb.Append("#00BB00");
                    messageLevel = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Info] ";
                    break;
                case LogLevel.Warn:
                    sb.Append("#FF6633");
                    messageLevel = "&nbsp;&nbsp; [Warning] ";
                    break;
                case LogLevel.Error:
                    sb.Append("#FF0000");
                    messageLevel = "&nbsp;&nbsp;&nbsp;&nbsp; [Error] ";
                    break;
                case LogLevel.Fatal:
                    sb.Append("#990000");
                    messageLevel = "[FatalError] ";
                    break;
                case LogLevel.Verbose:
                    sb.Append("#000000");
                    messageLevel = "&nbsp;&nbsp; [Verbose] ";
                    break;
                default:
                    return false;
            }

            sb.Append("\">");

            DateTime dateTime = DateTime.Now;

            sb.Append("[");
            sb.Append(dateTime.Hour).Append(":");
            sb.Append(dateTime.Minute).Append(":");
            sb.Append(dateTime.Second).Append(".");
            sb.Append(dateTime.Millisecond).Append("] ");
            sb.Append(messageLevel).Append(message).Append("</div><br />\n");

            return Write(sb.ToString());
        }
    }
}
